package com.tudouji.project.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.system.domain.Dict;
import com.tudouji.project.system.service.IDictService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 字典信息Controller
 * 
 * @author wf
 * @date 2021-01-25
 */
@RestController
@RequestMapping("/system/dict")
public class DictController extends BaseController
{
    @Autowired
    private IDictService dictService;

    /**
     * 查询字典信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:dict:list')")
    @GetMapping("/list")
    public TableDataInfo list(Dict dict)
    {
        startPage();
        List<Dict> list = dictService.selectDictList(dict);
        return getDataTable(list);
    }

    /**
     * 导出字典信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:dict:export')")
    @Log(title = "字典信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Dict dict)
    {
        List<Dict> list = dictService.selectDictList(dict);
        ExcelUtil<Dict> util = new ExcelUtil<Dict>(Dict.class);
        return util.exportExcel(list, "dict");
    }

    /**
     * 获取字典信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:dict:query')")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(dictService.selectDictById(guid));
    }

    /**
     * 新增字典信息
     */
    @PreAuthorize("@ss.hasPermi('system:dict:add')")
    @Log(title = "字典信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Dict dict)
    {
        return toAjax(dictService.insertDict(dict));
    }

    /**
     * 修改字典信息
     */
    @PreAuthorize("@ss.hasPermi('system:dict:edit')")
    @Log(title = "字典信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Dict dict)
    {
        return toAjax(dictService.updateDict(dict));
    }

    /**
     * 删除字典信息
     */
    @PreAuthorize("@ss.hasPermi('system:dict:remove')")
    @Log(title = "字典信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(dictService.deleteDictByIds(guids));
    }

    /**
     * @Author shaodong
     * @Description //通过字典类型获取值列表
     * @Date 11:07 2021/2/2
     * @Param
     * @return
     **/
    @RequestMapping(value = "/getDicts", method = RequestMethod.GET)
    public AjaxResult getDicts(@RequestParam("dicttype") Long dicttype){
        return AjaxResult.success(dictService.selectDictByType(dicttype));
    }




}
